package com.mashibing.exception;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Zyx
 * @since 2022/12/6 9:42 下午
 */

@Controller
public class ExceptionTestController {

    @RequestMapping("/npe")
    public String abc() {
        System.out.println("abc");
        String s = null;
        s.length();
        return "123";
    }

    @RequestMapping("/exp")
    public String bcd() throws ClassNotFoundException {
        System.out.println(123);
        throw new ClassNotFoundException("class not found");
    }


    @ExceptionHandler(NullPointerException.class)
    public String npe(NullPointerException e) {
        System.out.println(e);
        return e.toString();
    }

    @ExceptionHandler(RuntimeException.class)
    public String re(RuntimeException e) {
        System.out.println(e);
        return e.toString();
    }

    @ExceptionHandler
    public String eh(Exception e) {
        System.out.println(e);
        return e.toString();
    }


}
